package com.qls.ali.biz.service.fz.impl;


import com.qls.ali.biz.data.util.FzUtil;
import com.qls.ali.biz.service.fz.RoomService;
import com.qls.ali.biz.service.mybatis.HtSellRoomService;
import com.qls.core.entity.HtRoomType;
import com.qls.core.entity.HtSellRoom;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author yunchao
 */
@Service
@Slf4j
public class RoomServiceImpl implements RoomService {

    @Autowired
    private HtSellRoomService htSellRoomService;

    @Override
    public List<HtSellRoom> pushBatch(List<HtRoomType> htPhysicalRooms, String appKey, String secret, String session) {
        String ok = "xhotel_roomtype_add_response";
        List<HtSellRoom> htLogicRooms = new ArrayList<>();
        for (HtRoomType htPhysicalRoom : htPhysicalRooms) {
            Long roomCode = htPhysicalRoom.getRoomCode();
            String result = FzUtil.pushRoom(htPhysicalRoom, appKey, session, secret);
            if (!result.contains(ok)) {
                log.warn("{}-->{}，房型推送失败，失败原因：{}", htPhysicalRoom.getHotelCode(), roomCode, result);
                continue;
            }
            //htLogicRooms.addAll(htPhysicalRoom.getHtSellRoomList());
            Map<String, Object> roomCodeMap = new HashMap<>();
            roomCodeMap.put("room_code", roomCode);
            htLogicRooms.addAll(htSellRoomService.listByMap(roomCodeMap));
        }
        return htLogicRooms;
    }
}
